# -*- coding: utf-8 -*-
# @Author : zhangxuchuo
# @Date   : 2021/8/12
# @File   : Inter115_EntCurrBadCreditCheck.py
# @E-mail : wangbaoshan@bbdservice.com

'''eof
name:申请企业行内业务当前存在不良类信贷业务
code:Inter115_EntCurrBadCreditCheck
tableName:
columnName:
groups:企业通用模块
dependencies:WDXT_CLYW_IND
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import json
from datetime import datetime

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

def isfloat(x):
    '''
    判断x为float类型且大于等于0
    :param x:
    :return:
    '''
    try:
        if isinstance(float(x), float) and float(x)>=0:
            if str(x) in ['inf', 'infinity', 'INF', 'INFINITY', 'True']:
                return False
            else:
                return True
        else:
            return False
    except:
        return False

def Inter114_EntCurrConsCreditCheck():
    APIdata = WDXT_CLYW_IND.get('data')
    data = APIdata.get('businessArray', '')
    con = []
    if data == '':
        return '缺失值'
    else:
        for i in data:
            balance = i.get('balance', '')
            fiveClassifyResult = i.get('fiveClassifyResult', '')
            if balance not in null_type_list and fiveClassifyResult not in null_type_list:
                if isfloat(balance) and fiveClassifyResult in ['C', 'D', 'E']:
                    con.append(1)
                else:
                    con.append(0)
            else:
                con.append('None')

    if len(list(set(con))) == 1 and list(set(con))[0] == 'None':
        return '缺失值'
    factor = [i for i in con if i != 'None']
    return sum(factor)

result = Inter114_EntCurrConsCreditCheck